package com.eg366.nioLearn.baseSocket.chapter04;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;

/**
 * 一客户一线程 为每个连接创建一个新的线程来处理
 */
public class TCPEchoServerThread {
	public static void main(String[] args) throws IOException {
		args = new String[] { "1122" };
		if (args.length != 1) {
			throw new IllegalArgumentException("Parameter(s):<Port>");
		}

		int echoServerPort = Integer.parseInt(args[0]);

		ServerSocket servSock = new ServerSocket(echoServerPort);

		Logger logger = Logger.getLogger("practical");

		while (true) {
			Socket clntSock = servSock.accept();
			Thread thread = new Thread(new EchoProtocal(clntSock, logger));
			thread.start();
			logger.info("Create and started Thread " + thread.getName());
		}
	}
}
